<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<h2 class="formHeader" id="cartFormHeader">Your Cart</h2>

<form:form method="POST" commandName="cartForm"
	action="/film_rental/user/cart/rent" id="cartForm">

	<c:if test="${unavailableFilms.size() > 0}">
		<table class="formTable" id="unavailableTable">
			<tr class="formRow">
				<td class="formCell">Some of the films you selected were
					unavailable at your store. Visit <a
					href="/film_rental/user/profile"> your profile</a> to change your
					store.
				</td>
			</tr>
			<tr class="formRow">
				<td class="formCell"><h3>Unavailable Films</h3></td>
			</tr>
			<c:forEach items="${unavailableFilms}" var="film">
				<c:url value="/films/listings" var="filmListing">
					<c:param name="id" value="${film.filmId}"></c:param>
				</c:url>
				<tr class="formRow">
					<td class="formCell"><a href="${filmListing}"><c:out
								value="${film.title}"></c:out></a></td>
				</tr>
			</c:forEach>
		</table>
	</c:if>

	<table class="formTable" id="cartFormTable">
		<c:if test="${rentalsInCart.size() > 0}">
			<tr class="formRow">
				<td colspan="2" class="formCell"><h3>Film</h3></td>
				<td class="formCell"><h3>Cost</h3></td>
				<td class="formCell"><h3></h3></td>
			</tr>

		</c:if>


		<c:if test="${rentalsInCart.size() == 0}">
			<tr class="formRow">
				<td class="formCell">You have no rentals in your cart. <a
					href="/film_rental/user/search">Search for films here.</a></td>
			</tr>
		</c:if>

		<c:forEach items="${rentalsInCart}" var="rental">
			<c:url value="/films/listings" var="filmListing">
				<c:param name="id" value="${rental.inventory.film.filmId}"></c:param>
			</c:url>
			<c:url value="/user/cart/remove" var="removeFromCart">
				<c:param name="id" value="${rental.rentalId}"></c:param>
			</c:url>
			<tr class="formRow">
				<td class="formCell"><form:checkbox path="rentalsToPay"
						value="${rental.rentalId}" />
				<td class="formCell"><a href="${filmListing}"><c:out
							value="${rental.inventory.film.title}"></c:out></a></td>
				<td class="formCell">$<c:out
						value="${rental.inventory.film.rentalRate}"></c:out></td>
				<td class="formCell"><a href="${removeFromCart}">Remove
						from Cart</a></td>
			</tr>
		</c:forEach>
		<c:if test="${rentalsInCart.size() > 0}">
			<tr class="formRow">

				<td colspan="4" class="formCell"><input type="submit"
					value="Rent Selected Films" class="formButton" /></td>

			</tr>
		</c:if>

	</table>
</form:form>
